﻿using System;
using System.Data;
using msBsc.AppLogic.DataAlc;

namespace msBsc.WebUi
{
    public partial class wfCommercialTenantAudit : msBsc.Cls.BPageHt
    {

        CBizShpCommercialTenantInfo objShpCommercialTenantInfo = new CBizShpCommercialTenantInfo();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtId.Value = GetFormParam("ID");

                BindControls();
                ShowData(txtId.Value); 
            }
        }

        private void BindControls()
        {
            if (!IsPostBack)
            { 
            }
        }

        private void ShowData(string strId)
        {
            using (msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo oCBizShpCommercialTenantInfo = new AppLogic.DataAlc.CBizShpCommercialTenantInfo())
            {
                DataSet ds = oCBizShpCommercialTenantInfo.SelectCommercialTenantInfo(strId);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    this.AddPageRetRow("container", ds.Tables[0].Rows[0]);
                    if (ds.Tables[0].Rows[0]["COMM_TYPE_CID"].ToString() == "2")
                    { 
                        this.ExecJScript("$('#divinfo2').show();");
                    }
                    else
                    { 
                    }
                    ShowImgFile(ds.Tables[0].Rows[0]["COMM_TENANT_ID"].ToString());
                }
            }
        }

        private void ShowImgFile(string strRelId)
        {
            using (msBsc.AppLogic.DataAlc.CBizSysFile oCBizSysFile = new msBsc.AppLogic.DataAlc.CBizSysFile())
            {
                DataSet ds = oCBizSysFile.SelectByRelTypeRelId("0", "", strRelId);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["RELATION_TYPE_CID2"].ToString() == "SFZ_A")
                    {
                        this.ExecJScript("$('#imgsfza').attr('src', '" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(ds.Tables[0].Rows[i]["FILE_V_PATH"].ToString()) + "');");
                    }
                    else if (ds.Tables[0].Rows[i]["RELATION_TYPE_CID2"].ToString() == "SFZ_B")
                    {
                        this.ExecJScript("$('#imgsfzb').attr('src', '" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(ds.Tables[0].Rows[i]["FILE_V_PATH"].ToString()) + "');");
                    }
                    else if (ds.Tables[0].Rows[i]["RELATION_TYPE_CID2"].ToString() == "CMP_A")
                    {
                        this.ExecJScript("$('#imgcmpa').attr('src', '" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(ds.Tables[0].Rows[i]["FILE_V_PATH"].ToString()) + "');");
                    }
                    else if (ds.Tables[0].Rows[i]["RELATION_TYPE_CID2"].ToString() == "CMP_B")
                    {
                        this.ExecJScript("$('#imgcmpb').attr('src', '" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(ds.Tables[0].Rows[i]["FILE_V_PATH"].ToString()) + "');");
                    }
                }
            }
        }

      
        //重构基类的回调处理函数，以strAction属性来判断是什么类型的回调，该变量的值对应前台的ACTION参数，如：按钮的名称等
        public override void InitialByParam()
        {
            if (strAction == "btnAppConfirm")//根据传入的回调类型进行处理，这里响应编辑按钮
            {
                SetItemStatus(this.GetParamHtValue("ID"), "2");
                this.Alert("已成功审批，同意商家入驻！");
            }
            else if (strAction == "btnAppCancel")//根据传入的回调类型进行处理，这里响应编辑按钮
            {
                SetItemStatus(this.GetParamHtValue("ID"), "3");
                this.Alert("已拒绝商家入驻！");
            }

            base.InitialByParam();
        }
        private void SetItemStatus(string strId, string strStatus)
        {
            using (msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo oCBizShpCommercialTenantInfo = new AppLogic.DataAlc.CBizShpCommercialTenantInfo())
            {
                DataSet ds = oCBizShpCommercialTenantInfo.SelectById(strId);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (strStatus == "2" || strStatus == "3")
                    {
                        if (ds.Tables[0].Rows[0]["COMM_TENANT_SID"].ToString() != "1")
                        {
                            Alert("商家还未提交审批，不能执行审批操作！");
                            return;
                        }
                    }





                    ds.Tables[0].Rows[0]["COMM_TENANT_SID"] = strStatus;
                    oCBizShpCommercialTenantInfo.Update(ds);
                }
            }
            //DataSet ds = this.objItemSysTableProfile.SelectByIds(strIds);
            //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            //{
            //    if (ds.Tables[0].Rows[i]["REC_ACTIVE"].ToString() != strStatus)
            //    {
            //        ds.Tables[0].Rows[i]["REC_ACTIVE"] = strStatus == "True";
            //    }
            //}
            //if (ds.HasChanges())
            //{
            //    System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
            //    transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            //    transactionOption.Timeout = new TimeSpan(0, 10, 0);
            //    using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
            //    {
            //        objItemSysTableProfile.Update(ds);
            //        ds.AcceptChanges();

            //        ts.Complete();
            //        ts.Dispose();
            //        Epm.AppLogic.Framework.ApplicationInfo.STableProf = null;
            //    }
            //}
        }


    }
}